﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class Admin_Admin_Message : Admin, IRequiresSessionState
{
    private MessageBll _Message = null;
    protected MessageBll m_Message
    {
        get
        {
            MessageBll message;
            if (this._Message == null)
            {
                this._Message = new MessageBll(this.conn);
                message = this._Message;
            }
            else
            {
                message = this._Message;
            }
            return message;
        }
    }
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(8))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Meesgae");
            base.WriteRightErrMsg();
        }
        if (!base.admin.CheckAdminPower(8))
        {
            this.Panel_Add.Enabled = false;
        }
        if (!base.IsPostBack)
        {
            if (!base.admin.CheckAdminPower(8))
            {
                this.DeleteMessageButton.Enabled = false;
            }
        }
        if (Fetch.Get("action") == "add")
        {
            if (!base.IsPostBack)
            {
                this.Receiver.Attributes.Add("onchange", "FControl('" + this.Receiver.ClientID + "');");
                this.ShowUser.Attributes.Add("onclick", "SelectUser('" + this.SendName.ClientID + "');");
                GroupBll groupBll = new GroupBll(this.conn);
                this.SendGroup.DataSource = groupBll.GetGroupsNameID();
                this.SendGroup.DataBind();
                this.Panel_Add.Visible = true;
                this.panel_List.Visible = false;
            }
        }
        else
        {
            this.BindList();
        }
    }
    protected void BindList()
    {
        int num = Fetch.GetID("page");
        if (num <= 0)
        {
            num = 1;
        }
        int maxperpage = 15;
        if (this.GridView1.PageSize != 0)
        {
            maxperpage = int.Parse(this.GridView1.PageSize.ToString());
        }
        this.GridView1.DataSource = this.m_Message.GetMessages(num, maxperpage, "", "");
        this.GridView1.DataBind();
        this.PagePanel.Text = this.m_Message.GetPagePAnel("");
    }
    protected void Add_OnClick(object sender, EventArgs e)
    {
        if (this.Receiver.SelectedValue == "Users" && !this.SendName.Text.Trim().Contains(","))
        {
            UserBll userBll = new UserBll(this.conn);
            if (!userBll.CheckUserExist("UserName", this.SendName.Text.Trim()))
            {
                this.WriteErrMsg("", Language.Get("PassPort/NoUserName"), "");
            }
        }
        string text = "";
        foreach (ListItem listItem in this.SendGroup.Items)
        {
            if (listItem.Selected)
            {
                text = text + listItem.Value + ",";
            }
        }
        if (text != "")
        {
            text = text.Remove(text.Length - 1);
        }
        this.m_Message.AddMessage(this.Sender.Text, this.Receiver.SelectedValue, this.mtitle.Text, this.Content.Text, 0, 0, 1, 0, this.SendName.Text, text, 1);
        this.WriteSuccessMsg("", Language.GetAdminMsg("Message/SendSuccess"), "Admin_Message.aspx");
    }
    protected void Dele_Message(object sender, CommandEventArgs e)
    {
        if (!base.admin.CheckAdminPower(8))
        {
            base.WriteRightErrMsg();
        }
        this.m_Message.DeleteMessage(int.Parse(e.CommandArgument.ToString()));
        this.BindList();
    }
    protected void DeleteMessageButton_Click(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(8))
        {
            base.WriteLog("Delete", Language.GetAdminMsg("Log/Access", "0"), "Meesgae");
            base.WriteRightErrMsg();
        }
        string text = this.CheckNumList(base.Request["chk_select"]);
        if (text != string.Empty)
        {
            this.m_Message.DeleteMessage(text);
            this.BindList();
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        bool flag = base.admin.CheckAdminPower(8);
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            gridViewRow.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
            gridViewRow.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
            if (!flag)
            {
                gridViewRow.Cells[6].Enabled = false;
            }
            string text = gridViewRow.Cells[5].Text;
            if (text == null)
            {
                goto IL_FE;
            }
            if (!(text == "0"))
            {
                if (!(text == "1"))
                {
                    goto IL_FE;
                }
                gridViewRow.Cells[5].Text = Language.GetAdminMsg("Message/ReadStatus1");
            }
            else
            {
                gridViewRow.Cells[5].Text = Language.GetAdminMsg("Message/ReadStatus0");
            }
        IL_11F:
            Label label = (Label)gridViewRow.Cells[3].FindControl("Title");
            Label label2 = (Label)gridViewRow.Cells[3].FindControl("Content");
            if (label != null && label2 != null)
            {
                label.Attributes.Add("onMouseOver", "ShowDiv('" + label2.ClientID + "')");
                label.Attributes.Add("onMouseOut", "HiddenDiv('" + label2.ClientID + "')");
            }
            continue;
        IL_FE:
            gridViewRow.Cells[5].Text = Language.GetAdminMsg("Message/ReadStatus0");
            goto IL_11F;
        }
    }
}
